package com.cn.admin.controller;


import com.cn.admin.entity.User;
import com.cn.admin.entity.UserQuery;
import com.cn.admin.node.MenuNode;
import com.cn.admin.service.UserService;
import com.cn.admin.vo.ResponseObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/admin")
public class UserController {


    @Autowired
    private UserService userService;

    @PostMapping("/user/list")
    public Object list(){

        List<User> users = userService.selectByExample(new UserQuery());

        return ResponseObject.success(users);
    }

    @PostMapping("/user/get")
    public Object get(Long id){

        User user = userService.selectByPrimaryKey(id);

        return ResponseObject.success(user);
    }

    @PostMapping("/user/insert")
    public Object get(User user){

        int i = userService.insertSelective(user);

        return ResponseObject.success(i);
    }


    @PostMapping("/user/edit")
    public Object edit(User user){

        int i = userService.updateByPrimaryKeySelective(user);

        return ResponseObject.success(i);
    }

    @PostMapping("/user/register")
    public Object register(User user){

        int i = userService.register(user);

        return ResponseObject.success(i);
    }
}
